#ifndef METACLASS_H
#define METACLASS_H

#include <QObject>
#include <QString>
#include <QMap>
#include <QLibrary>
//#include "loader.h"

#include "metafield.h"

#include <iostream>

using namespace std;

typedef QObject* (*lCreate)(QString);

class MetaClass : public QObject
{
    Q_OBJECT
public:
    explicit MetaClass(QObject *parent = 0);
    ~MetaClass();
    explicit MetaClass(const QString& className, const QString& libName, const QString& libPath = "");

    QString const & getLibName() const;
    void setLibName(const QString& name);

    QString const & getLibPath() const;
    void setLibPath(const QString& path);

    QString const & getClassName() const;
    void setClassName(const QString& name);

    QString getFullName() const;

    QMap<QString, MetaField*>& getFields() ;
    void addField(MetaField* field);

    //static QObject* getInstance(const QString& id);

    QObject* instantiate() const ;
    //QObject* instantiate(const QString& id);
    static QObject* instantiate(const QString& libPath, const QString& className);

private:
    QString libName;
    QString libPath;
    QString className;
    QMap<QString, MetaField*> fields;
    static QMap<QString, QObject*> *instanceMap;

protected:
    static QObject* resolveClass(QLibrary* lib, const QString& className) ;

signals:

public slots:

};

#endif // METACLASS_H
